package com.cloud.spring.demo.controller;

import com.cloud.spring.demo.entity.Address;
import com.cloud.spring.demo.entity.User;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;

@RestController
public class UserController {

    @GetMapping("getUser")
    public User getUser(int id) {
        return createUser(id);
    }

    @PostMapping("getUserList")
    public List<User> getUserList(@RequestBody User user) {
        return Arrays.asList(user, user, user);
    }

    @PostMapping("saveUserList")
    public List<User> saveUserList(@RequestBody List<User> userList) {
        return userList;
    }

    public User createUser(int id) {
        User user = new User();
        user.setId(id);
        user.setName("tom");
        user.setCreateTime(LocalDateTime.now());
        Address address = new Address();
        address.setId(id);
        address.setMessage("YanTai");
        user.setAddress(address);
        return user;
    }
}
